from service.strategyService.BaseStrategyServiceModel import BaseStrategyServiceModel

default_profit_rate = 0.4
default_concentration_90 = 0.12
default_concentration_70 = 0.1

class LowIntensiveChipStrategy(BaseStrategyServiceModel):
    def __init__(self, profit_rate, concentration_90, concentration_70):
        super().__init__()
        self.profit_rate = float(profit_rate) if profit_rate is not None else default_profit_rate
        self.concentration_90 = float(concentration_90) if concentration_90 is not None else default_concentration_90
        self.concentration_70 = float(concentration_70) if concentration_70 is not None else default_concentration_70

    def select(self, data):
        profit_rate = data['profit_rate'].values
        concentration_90 = data['concentration_90'].values
        concentration_70 = data['concentration_70'].values
        close = data['close'].values
        avg = data['avg'].values
        # 筛选条件
        """
        1. 获利比例大于0.4
        2. 90集中度小于0.12
        3. 70集中度小于0.1
        4. 平均成本小于当天收盘价
        """
        conditions = (
                (profit_rate > self.profit_rate).all() and
                (concentration_90 < self.concentration_90).all() and
                (concentration_70 < self.concentration_70).all() and
                (avg < close).all()
        )
        if conditions:
            return True
        else:
            return False